﻿using System;
using Ue.CQRS.Samples.Application.Command.Repositories;
using Ue.CQRS.Samples.Domain.Models;
using Ue.CQRS.Samples.Infrastructure;

namespace Ue.CQRS.Samples.Application.Command.Services
{
    public class BookService : Single<BookService>
    {
        private IDomainRepository repository;

        public BookService()
        {
            this.repository = new DomainRepository();
        }

        public Guid Add(string name,string description,string author,string isbn,int paper,int total)
        {
            var book = new Book(name, description, author, isbn, paper, total);
            this.repository.Save(book);
            return book.ID;
        }
         
        public void Edit(Guid id, string name, string description, string author, string isbn, int paper)
        {
            var book = this.repository.Load<Book>(id);
            book.UpdateProfile(name, description, author, isbn, paper);
            this.repository.Save(book);
        }

        public void Delete(Guid id)
        {
            var book = this.repository.Load<Book>(id);
            book.Remove();
            this.repository.Save(book);
        }

        /// <summary>
        /// 上架
        /// </summary>
        /// <param name="book"></param>
        public void OnSell(Guid bookId)
        {
            //var book = new Book(bookContract);

            //book.OnSell();
        }

        /// <summary>
        /// 下架
        /// </summary>
        /// <param name="book"></param>
        public void OffSell(Guid bookId)
        {
            //var book = this.repository.Get<Book>(bookId);

            //book.OffSell();
        }

        /// <summary>
        /// 借阅
        /// </summary>
        /// <param name="card"></param>
        /// <param name="book"></param>
        public void Borrow(Guid cardId, Guid bookId)
        {
            //var card = this.repository.Get<BorrowingCard>(cardId);
            //var book = this.repository.Get<Book>(bookId);

            //card.Borrowing(book);
        }
    }
}